package org.nox.helloseries.server;

import java.io.FileOutputStream;

import org.apache.commons.io.FileUtils;
import org.nox.helloseries.server.services.AsyncSearchTimer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * Start simple console calls
 */
public class Launcher
{
    private static final Logger LOG = LoggerFactory.getLogger( Launcher.class );

    public static void main( String[] args )
    {
        // Tentative de lock pour éviter les multiples instances
        try (FileOutputStream lockFile = new FileOutputStream( FileUtils.getTempDirectoryPath() + "\\" + "lock" ))
        {

            if ( lockFile.getChannel().tryLock() != null )
            {
                // Lancement job asynchrone
                new AsyncSearchTimer().start();
            }
            else
            {
                LOG.error( "Application déjà lancée" );
                System.exit( 0 );
            }
        }
        catch ( Exception e )
        {
            LOG.error( "{}", e );
        }
    }
}
